home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / oper_sys / prospero / propsero.lha / prospero-beta.4.2e / user / pstatus.c < prev    next >
C/C++ Source or Header  |  1992-02-10  |  2KB  |  100 lines

  1. /*
  2.  * Copyright (c) 1989, 1990, 1991 by the University of Washington
  3.  *
  4.  * For copying and distribution information, please see the file
  5.  * <uw-copyright.h>.
  6.  */
  7.  
  8. #include <uw-copyright.h>
  9. #include <stdio.h>
  10.  
  11. #include <pfs.h>
  12. #include <perrno.h>
  13. #include <pprot.h>
  14. #include <rdgram.h>
  15.  
  16. extern int    perrno;
  17. int        pfs_debug = 0;
  18.  
  19. main(argc,argv)
  20.     int        argc;
  21.     char    *argv[];
  22.     {
  23.         PTEXT        request;
  24.     PTEXT        resp;
  25.  
  26.     char        dirhst[40];
  27.     char        *command = "STATUS";
  28.  
  29.     argc--;argv++;
  30.  
  31.     while (argc > 0 && **argv == '-') {
  32.  
  33.         switch (*(argv[0]+1)) {
  34.         
  35.         case 'D':
  36.         pfs_debug = 1; /* Default debug level */
  37.         sscanf(argv[0],"-D%d",&pfs_debug);
  38.         break;
  39.  
  40.         case 'N':  /* Priority (nice) */
  41.         rdgram_priority = RDGRAM_MAX_PRI; /* Use this if no # */
  42.         sscanf(argv[0],"-N%d",&rdgram_priority);
  43.         if(rdgram_priority > RDGRAM_MAX_SPRI) 
  44.             rdgram_priority = RDGRAM_MAX_PRI;
  45.         if(rdgram_priority < RDGRAM_MIN_PRI) 
  46.             rdgram_priority = RDGRAM_MIN_PRI;
  47.         break;
  48.  
  49.         case 'v':
  50.         command = "VERSION";
  51.         break;
  52.         
  53.         default:
  54.         fprintf(stderr,
  55.             "Usage: pstatus [-v] [host name]\n");
  56.         exit(1);
  57.         }
  58.         argc--, argv++;
  59.     }
  60.  
  61.     request = ptalloc();
  62.  
  63.     gethostname(dirhst,40);
  64.  
  65.     if(argc > 1) {
  66.         fprintf(stderr,"Usage: pstatus [host name]\n");
  67.         exit(1);
  68.     }
  69.  
  70.     if(argc > 0)
  71.         strcpy(dirhst,argv[0]);
  72.  
  73.     sprintf(request->start,"%s\n",command);
  74.  
  75.     request->length = strlen(request->start);
  76.  
  77.     printf("Sending message to %s...\n%",dirhst);
  78.     
  79.     resp = dirsend(request,dirhst,0);
  80.  
  81.     if(resp == NULL) {
  82.         perrmesg("pstatus failed: ", 0, NULL);
  83.         exit(1);
  84.     }
  85.  
  86.     if(pwarn) pwarnmesg("WARNING: ",0,NULL);
  87.  
  88.     while(resp->next) resp = resp->next;
  89.  
  90.     printf("Response:\n%s",resp->start);
  91.  
  92.     if(*(resp->start+strlen(resp->start)-1) != '\n') 
  93.         printf("\n");
  94.  
  95.     ptlfree(resp);
  96.     exit(0);
  97.  
  98.     }
  99.  
  100.